<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<title>信息管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="/style/basic_layout.css" rel="stylesheet" type="text/css">
    <link href="/style/common_style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/js/jquery/jquery.js"></script>
    <script type="text/javascript" src="/artDialog/jquery.artDialog.js?skin=blue"></script>
    <script type="text/javascript" src="/js/jquery/plugins/jquery.form.min.js"></script>
    <script type="text/javascript" src="/js/commonAll.js"></script>
    <script type="text/javascript" src="/js/jquery/plugins/jquery.validate.js"></script>
    <script type="text/javascript">
    	$(function(){
    		$("#editForm").validate({
   			rules: {
    				sn:{
    					required:true,
    					maxlength:5
    				},
  					name:{
  						required:true,
  						maxlength:50
  					},
					costPrice:{
						required:true,
						number:true
					},
					salePrice:{
						required:true,
						number:true
					},
					brandId:"required"
   				},
   			messages: {
    				sn:{
    					required:"必填",
    					maxlength:"最多填5字符"
    				},
  					name:{
  						required:"必填",
  						maxlength:"最多填20字符"
  					},
					costPrice:{
						required:"必填",
						number:"只能输入数字"
					},
					salePrice:{
						required:"必填",
						number:"只能输入数字"
					},
					brandId:"必填",
   				}	
    		});
    	});
    	
    	$(function(){
	    	$("#editForm").ajaxForm(function(data){
	    		if(data.flag){
	    			myconfirm("保存成功","succeed",function(){
	    				window.location.href="/product/list";
	    			},false);
	    		}else{
	    			myconfirm("保存失败","error",true,false);
	    		}
	    	});
	    });
    </script>
</head>
<body>
<form name="editForm" action="/product/saveOrUpdate" method="post" id="editForm" enctype="multipart/form-data">
	<div id="container">
		<div id="nav_links">
			<span style="color: #1A5CC6;">品牌${empty product ? '添加' : '编辑'}</span>
			<div id="page_close">
				<a>
					<img src="/images/common/page_close.png" width="20" height="20" style="vertical-align: text-top;"/>
				</a>
			</div>
		</div>
		<div class="ui_content">
			<table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
				<tr>
					<td>
						<input type="hidden" name="id" value="${product.id}">
					</td>
				</tr>
				<tr>
					<td class="ui_text_rt" width="140">商品编码</td>
					<td class="ui_text_lt">
						<input name="sn" class="ui_input_txt02" value="${product.sn}"/>
					</td>
				</tr>
				<tr>
					<td class="ui_text_rt" width="140">商品名称</td>
					<td class="ui_text_lt">
						<input name="name" class="ui_input_txt02" value="${product.name}"/>
					</td>
				</tr>
				<tr>
					<td class="ui_text_rt" width="140">成本价格</td>
					<td class="ui_text_lt">
						<input name="costPrice" class="ui_input_txt02" value="${product.costPrice}"/>
					</td>
				</tr>
				<tr>
					<td class="ui_text_rt" width="140">销售价格</td>
					<td class="ui_text_lt">
						<input type="text" name="salePrice" class="ui_input_txt02" value="${product.salePrice}"/>
					</td>
				</tr>
				 <tr>
                    <td class="ui_text_rt" width="140">商品品牌</td>
                    <td class="ui_text_lt">
                        <select name="brandId" class="ui_select01 brand">
                           <option value="-1">全部</option>
                        	<c:forEach items="${brands}" var="b">
                          	  <option value="${b.id}" ${b.id==product.brandId ? 'selected':''}>${b.name}</option>
                        	</c:forEach>
                        </select>
                        <input type="hidden" name="brandName">
                        <script type="text/javascript">
                        	$(".brand").change(function (){
                        		var brandName = $(".brand option:selected").text();
                        		$("[name='brandName']").prop("value",brandName);
                        	});
                        </script>
                    </td>
                </tr>
                <tr>
					<td class="ui_text_rt" width="140">商品图片</td>
					<td class="ui_text_lt">
						<input type="file" name="pic" />
						<img width="80px" src="${product.imagePath}">
						<input type="hidden"  name="imagePath" value="${product.imagePath}">
					</td>
				</tr>
                <tr>
					<td class="ui_text_rt" width="140">商品简介</td>
					<td class="ui_text_lt">
						<textarea rows="10" cols="30" name="intro">${product.intro}</textarea>
					</td>
				</tr>
					<td>&nbsp;</td>
					<td class="ui_text_lt">
						&nbsp;<input type="submit" value="确定${empty product ? '添加' : '编辑'}" class="ui_input_btn01"/>
						&nbsp;<input id="cancelbutton" type="reset" value="重置" class="ui_input_btn01"/>
					</td>
				</tr>
			</table>
		</div>
	</div>
</form>
</body>
</html>